package com.kitty.common.schedule.task;

import com.kitty.common.cache.RedisService;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.drop.newservice.NewDropService;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@Slf4j
public class SendYuanBaoTask implements ScheduledOfTask {
    @Autowired
    NewDropService newDropService;
    @Autowired
    RedisService redisService;
    @Override
    public void execute() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        RoleService roleService = SpringUtils.getRoleService();
        Collection<Role> roles = DataCache.ONLINE_ROLES.values();
        String online_reward = DataCache.REDIS_DATA.get("online_reward");
        for (Role role : roles) {
            //假人忽略在线奖励
            if(role.getAitype() == 1 || role.getAitype() == 2){
                continue;
            }
            MessagePusher.pushMessage(role, new RespNotifyMiscEx("#Y收到在线奖励#n"));
            newDropService.addRewardTask(role,online_reward,"");
            //SpringUtils.getMailService().buchang(role, "积分", 60);

//            MessagePusher.pushMessage(role, new RespNotifyMiscEx("收到在线奖励" + 3000 + "金元宝！！"));
//            roleService.addGold(role, 3000, Reason.AGENT_GM);
        }
        stopWatch.stop();
        log.info("发送在线奖励，用时{}毫秒", stopWatch.getTime());
    }

}
